/*
* 1videoConference -- An open source video conferencing platform.
*
* Copyright (C) 2007 - 2008, Adiance Technologies Pvt. Ltd.
*
* Hardik Sanghvi <hardik.sanghvi @adiance.com>
*
* See http://www.1videoconference.org for more information about
* the 1videoConference project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, forums and mailing lists
* for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.ServiceModel;
using _videoConference.BAL;

namespace _videoConference
{
    sealed public partial class Config : Page,IDisposable
    {
        System.Data.DataSet ds = new System.Data.DataSet();
        IAddPage ia = new IAddPage();
        private bool disposed = false;

        public Config()
        {
            InitializeComponent();
            UserInfo.MyCurrentPage = "Config";
            this.ShowsNavigationUI = false;
            
            try
            {
                ds = ia.getconfig();
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        switch (ds.Tables[0].Rows[i][0].ToString())
                        {
                            case "SMTPServer":
                                txtSMTPServer.Text = ds.Tables[0].Rows[i][1].ToString();
                                break;

                            case "SMTPPort":
                                txtSMTPPort.Text = ds.Tables[0].Rows[i][1].ToString();
                                break;

                            case "SMTPUserName":
                                txtSMTPUserName.Text = ds.Tables[0].Rows[i][1].ToString();
                                break;

                            case "SMTPPassword":
                                txtSMTPPassword.Text = ds.Tables[0].Rows[i][1].ToString();
                                break;

                            case "SMTPSSL":
                                if (ds.Tables[0].Rows[i][1].ToString() == "True")
                                {
                                    chkSMTPSSL.IsChecked = true;
                                }
                                else if (ds.Tables[0].Rows[i][1].ToString() == "False")
                                {
                                    chkSMTPSSL.IsChecked = false;
                                }
                                break;

                            case "AsteriskServer":
                                txtAsteriskServer.Text = ds.Tables[0].Rows[i][1].ToString();
                                break;
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "1videoConference--:--App.xaml.cs--:--Config()--:----:--");
                clsUtility.LogException = exp;               
            }
        }

        void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ia.setconfig(txtSMTPServer.Text, txtSMTPPort.Text, txtSMTPUserName.Text, txtSMTPPassword.Text, txtAsteriskServer.Text, chkSMTPSSL.IsChecked.ToString());                
                NavigationService.GetNavigationService(this).Navigate(new Uri("LogOn.xaml", UriKind.RelativeOrAbsolute));
                return;
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "1videoConference--:--Config.xaml.cs--:--btnUpdate_Click()--:----:--");
                clsUtility.LogException = exp;
            }
        }

        void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                NavigationService.GetNavigationService(this).Navigate(new Uri("LogOn.xaml", UriKind.RelativeOrAbsolute));
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "1videoConference--:--Config.xaml.cs--:--btnCancel_Click()--:----:--");
                clsUtility.LogException = exp;                
            }
        }

        void lblSMTPSSL_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                chkSMTPSSL.IsChecked = !chkSMTPSSL.IsChecked;
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "1videoConference--:--Config.xaml.cs--:--lblSMTPSSL_PreviewMouseDown()--:----:--");
                clsUtility.LogException = exp;                
            }
        }

         public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);    
        }

         private void Dispose(bool disposing)
        {
            if(!this.disposed)
            {
                if(disposing)
                { 
                   
                }        
                disposed = true;

            }
        }

        ~Config()
        {
            Dispose(false);
        }



        #region for PODOpes

        public void logolink(object o, MouseButtonEventArgs e)
        {
            try
            {
                vclink.NavigateUri = new Uri("http://www.1videoconference.com", false);
                vclink.TargetName = "window1";
                vclink.DoClick();
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "1videoConference--:--Config.xaml.cs--:--logolink()--:----:--");
                clsUtility.LogException = exp;               
            }
        }
        #endregion
    }
}